//记录查询条件用于回显
// var searchParamArr={"code":-1,"param":""};
function findBxinfos(CertusFormAjax, $scope) {
    // 资产信息
    var seatColumns = [{
        id: 'accountApplyDate',
        title: '报销时间',
        type: 'date',
        width: 100,
        format: 'yyyy/MM/dd',
        otype: 'time_stamp_ms',
        columnClass: 'text-center'
    }, {
        id: 'deptName',
        title: '归属部门',
        type: 'string',
        width: 200,
        columnClass: 'text-center'
    }, {
        id: 'type',
        title: '类型',
        type: 'string',
        width: 75,
        columnClass: 'text-center',
        resolution: function (value, record) {
            var content = '';
            var type = record.type;
            if (type == "XJBX") {
                content = "现金报销";
            }else if (type == "ZDBX") {
                content = "招待报销";
            } else {
                content = "差旅报销";
            }
            return content;
        }
    }, {
        id: 'accountUser',
        title: '报销人',
        type: 'string',
        width: 75,
        columnClass: 'text-center'
    }, {
        id: 'indoorTraffic',
        title: '市内交通金额',
        type: 'string',
        hideType: 'lg|md|sm|xs',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'officeAmount',
        title: '办公品金额',
        type: 'string',
        hideType: 'lg|md|sm|xs',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'receptionAmount',
        title: '招待应酬金额',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'consumablePrice',
        title: '易耗品金额',
        type: 'string',
        hideType: 'lg|md|sm|xs',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'lunchMoney',
        title: '午餐金额',
        type: 'string',
        hideType: 'lg|md|sm|xs',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'phoneMoney',
        title: '通讯金额',
        type: 'string',
        hideType: 'lg|md|sm|xs',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'carMoney',
        title: '车辆费金额',
        type: 'string',
        hideType: 'lg|md|sm|xs',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'elseMoney',
        title: '其他金额',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'accountSum',
        title: '总金额',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'projName',
        title: '报销项目',
        type: 'string',
        columnClass: 'text-center'
    }, {
        id: 'accountReason',
        title: '报销事由',
        type: 'string',
        hideType: 'lg|md|sm|xs',
        columnClass: 'text-left'
    }];

    this.search = function () {
        var deptCode = $("#deptCode").val();
        var accountUser = $("#searchParam").val();
        var beginTime = $("#beginTime").val();
        var endTime = $("#endTime").val();
        var type = $("#type").val();
        var reason = $("#reason").val();

        $("#bxContainer").empty();
        $("#bxToolBarContainer").empty();
        // 开启
        var index = layer.load(1);
        CertusFormAjax.ajax('findBxInfos', {
            "deptCode": deptCode,
            "accountUser": accountUser,
            "beginTime": beginTime,
            "endTime": endTime,
            "type": type,
            "reason": reason
        }, function (result) {
            var telOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '报销列表',
                datas: result.data,
                columns: seatColumns,
                gridContainer: 'bxContainer',
                toolbarContainer: 'bxToolBarContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var telGrid = $.fn.dlshouwen.grid.init(telOption);
            telGrid.load();
            // 关闭
            layer.close(index);
        });
        CertusFormAjax.ajax('getBxMoney', {
            "deptCode": deptCode,
            "accountUser": accountUser,
            "beginTime": beginTime,
            "endTime": endTime,
            "type": type,
            "reason": reason
        }, function (result) {
            var data = result.data;
            $scope.indoorTrafficMoney = data.indoorTrafficMoney;
            $scope.officeAmountMoney = data.officeAmountMoney;
            $scope.receptionAmountMoney = data.receptionAmountMoney;
            $scope.consumablePriceMoney = data.consumablePriceMoney;
            $scope.lunchMoney = data.lunchMoney;
            $scope.phoneMoney = data.phoneMoney;
            $scope.carMoney = data.carMoney;
            $scope.elseMoney = data.elseMoney;
            $scope.accountSum = data.accountSum;
        });
    };
    var cgColumns = [{
        id: 'cgApplyDate',
        title: '采购时间',
        type: 'date',
        width: 100,
        format: 'yyyy/MM/dd',
        otype: 'time_stamp_ms',
        columnClass: 'text-center'
    }, {
        id: 'accountSum',
        title: '采购金额',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'cgReason',
        title: '采购原因',
        type: 'string',
        columnClass: 'text-left'
    }, {
        id: 'cgProNo',
        title: '采购项目',
        type: 'string',
        width: 200,
        columnClass: 'text-center'
    }, {
        id: 'annexe',
        title: '采购文档',
        type: 'string',
        hideType: 'lg|md|sm|xs',
        columnClass: 'text-center'
    }];
    this.search2 = function () {
        var beginTime = $("#beginTime2").val();
        var endTime = $("#endTime2").val();
        var reason = $("#cgreason").val();

        $("#cgContainer").empty();
        $("#cgToolBarContainer").empty();
        // 开启
        var index = layer.load(1);
        CertusFormAjax.ajax('findCgList', {
            "beginTime": beginTime,
            "endTime": endTime,
            "reason": reason
        }, function (result) {
            var telOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '采购列表',
                datas: result.data,
                columns: cgColumns,
                gridContainer: 'cgContainer',
                toolbarContainer: 'cgToolBarContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var telGrid = $.fn.dlshouwen.grid.init(telOption);
            telGrid.load();
            // 关闭
            layer.close(index);
        });

        CertusFormAjax.ajax('getCgMoney', {
            "beginTime": beginTime,
            "endTime": endTime,
            "reason": reason
        }, function (result) {
            $scope.cgSum = result.data;
        });
    };
    $(".psearch4").on('click', function () {
        $("#deptCode").val("");
        $("#searchParam").val("");
        $("#accountName").val("");
        $("#beginTime").val("");
        $("#endTime").val("");
        $("#type").val("");
        $("#reason").val("");
    });
    $(".psearch3").on('click', function () {
        $("#beginTime2").val("");
        $("#endTime2").val("");
        $("#cgreason").val("");
    });
    // CertusFormAjax.ajax('companyListByViewCode',{},function (response) {
    //     $scope.comps = JSON.parse(response.data);
    // });

    // CertusFormAjax.ajax("isCrcd", {
    //     "code": "ZWGL"
    // }, function (response) {
    //     var data = JSON.parse(response.data);
    //     if (data.isTrue == true) {
    //         $scope.isCrud = true;
    //     } else {
    //         $scope.isCrud = false;
    //     }
    //     search($scope.isCrud);
    // });

    CertusFormAjax.ajax("deptListByCompany", {}, function (response) {
        $scope.depts = response.data;
    });

    //归属人
    CertusFormAjax.ajax("findSpUserList", {}, function (response) {
        var nhlTeams = [];
        var data = response.data;
        for (var i = 0; i < data.length; i++) {
            var arr = {};
            arr.name = data[i].userName + "[" + data[i].positonName + "]";
            arr.id = data[i].userId;
            nhlTeams.push(arr);
        }
        //自动补全
        var nhl = $.map(nhlTeams, function (obj) {
            return {
                value: obj.name,
                data: {
                    category: obj.id
                }
            };
        });
        // Initialize autocomplete with local lookup:
        $('#accountName').devbridgeAutocomplete({
            lookup: nhl,
            minChars: 1,
            onSelect: function (suggestion) {
                $("#searchParam").val(suggestion.data.category);
            },
            showNoSuggestionNotice: true,
            noSuggestionNotice: 'Sorry, no matching results'
        });
    });
    $(".psearch").on('click', function () {
        search();
    });
    $(".psearch2").on('click', function () {
        search2();
    });
}